<template>
  <dialog-box
    :isDialog="false"
    ref="myDialog"
    :showFooter="true"
    width="500px"
    @close="close"
    @sureHandle="sureHandle"
    :isFooterSlot="true"
    :title="state.title"
  >
    <template v-slot:dialogMain>
      <div>
        <el-form
          ref="ruleFormRef"
          :model="ruleForm"
          :rules="rules"
          label-width="auto"
          class="demo-ruleForm"
          size="default"
          status-icon
        >
          <el-form-item label="审批意见" prop="name">
            <el-radio-group v-model="ruleForm.name">
              <el-radio :value="1">通过</el-radio>
              <el-radio :value="2">不通过</el-radio>
            </el-radio-group>
          </el-form-item>
          <el-form-item label="审批说明" prop="desc">
            <el-input v-model="ruleForm.desc" type="textarea" />
          </el-form-item>
        </el-form>
      </div>
    </template>
  </dialog-box>
</template>

<script setup lang="ts">
import dialogBox from "@/components/dialog-box/index.vue";
import { onMounted, computed, reactive, toRefs, ref } from "vue";
import type { ComponentSize, FormInstance, FormRules } from "element-plus";
const myDialog = ref(null);

const ruleFormRef = ref<FormInstance>();
    interface RuleForm {
  name: number;
  desc: string;
}
const ruleForm = reactive<RuleForm>({
  name: 1,
  desc: "",
});

let state = reactive({
  title: "",
});
// 定义完成后，用defineExpose()暴露给父组件
const open = (title: string) => {
  state.title = title;
  myDialog.value.handleOpen();
};
const close = () => {
  resetForm();
  myDialog.value.handleClose();
};
const sureHandle = () => {
  submitForm();
};
defineExpose({
  open,
  close,
});


const submitForm = async () => {
  if (!ruleFormRef) return;
  console.log(ruleFormRef, "23232");
  await ruleFormRef.value?.validate((valid, fields) => {
    if (valid) {
      console.log("submit!");
    } else {
      console.log("error submit!", fields);
    }
  });
};

const resetForm = () => {
  if (!ruleFormRef) return;
  ruleFormRef.value?.resetFields();
};
const rules = reactive<FormRules<RuleForm>>({
  name: [
    { required: true, message: "Please input Activity name", trigger: "blur" },
  ],
});
</script>

<style scoped>
h2 {
  margin-bottom: 20px;
}
.mb-20 {
  margin-bottom: 20px;
}
.mr-10 {
  margin-right: 10px;
}
.ml-10 {
  margin-left: 10px;
}
.steps-box {
  width: 300px;
  margin: 0 auto 30px;
}
.title-box {
  display: flex;
  align-items: center;
}
.seach-box {
  display: flex;
  padding: 0 10px;
  box-sizing: border-box;
}
.footer-btns {
  width: 100%;
  display: flex;
  justify-content: center;
}
</style>
